﻿namespace DiffuseEnjoyIdle.Core.Utility
{
    /// <summary>
    /// 时间戳和日期的转化
    /// </summary>
    public static class DateTimeUtility
    {
        /// <summary>
        ///  时间戳转本地时间-时间戳精确到秒
        /// </summary> 
        public static DateTime ToLocalTimeDateBySeconds(long unix)
        {
            var dto = DateTimeOffset.FromUnixTimeSeconds(unix);
            return dto.ToLocalTime().DateTime;
        }

        /// <summary>
        ///  时间转时间戳Unix-时间戳精确到秒
        /// </summary> 
        public static long ToUnixTimestampBySeconds(DateTime dt)
        {
            var dto = new DateTimeOffset(dt);
            return dto.ToUnixTimeSeconds();
        }


        /// <summary>
        ///  时间戳转本地时间-时间戳精确到毫秒
        /// </summary> 
        public static DateTime ToLocalTimeDateByMilliseconds(long unix)
        {
            var dto = DateTimeOffset.FromUnixTimeMilliseconds(unix);
            return dto.ToLocalTime().DateTime;
        }

        /// <summary>
        ///  时间转时间戳Unix-时间戳精确到毫秒
        /// </summary> 
        public static long ToUnixTimestampByMilliseconds(DateTime dt)
        {
            var dto = new DateTimeOffset(dt);
            return dto.ToUnixTimeMilliseconds();
        }

        ///// <summary>  
        ///// 将DateTime时间格式转换为Unix时间戳格式  
        ///// </summary>  
        ///// <param name="time">时间</param>  
        ///// <returns>long</returns>  
        //public async Task<string> Timestamp()
        //{
        //    await Task.Delay(0);
        //    long ts = (DateTime.Now.Ticks - 621356256000000000) / 10000;
        //    return ts.ToString();
        //}
    }
}
